mod itgr;
mod saturated_reachability;
mod xie_beerel;
use crate::algorithms::eval_dynamic::_attractors::itgr::interleaved_transition_guided_reduction;
use crate::algorithms::eval_dynamic::_attractors::xie_beerel::xie_beerel_attractors;
use biodivine_lib_param_bn::{
biodivine_std::traits::Set,
symbolic_async_graph::{GraphColoredVertices, GraphColors, SymbolicAsyncGraph},
};
pub fn sort_colors_by_attr_num(graph: &SymbolicAsyncGraph) -> Vec<GraphColors> {
let (universe, active_variables) =
interleaved_transition_guided_reduction(graph, graph.mk_unit_colored_vertices());
let mut colors_by_num_attrs = Vec::new();
colors_by_num_attrs.push(graph.mk_unit_colors());
xie_beerel_attractors(graph, &universe, &active_variables, |component| {
process_component(&mut colors_by_num_attrs, &component);
});
colors_by_num_attrs
}
fn process_component(colors_by_num_attrs: &mut Vec<GraphColors>, component: &GraphColoredVertices) {
let component_colors = component.colors();
let tmp_colors_by_num_attrs = colors_by_num_attrs.clone();
for (num_attrs, color_set) in tmp_colors_by_num_attrs.into_iter().enumerate().rev() {
let intersect = color_set.intersect(&component_colors);
if intersect.is_empty() {
continue;
}
if num_attrs == colors_by_num_attrs.len() - 1 {
colors_by_num_attrs.push(intersect.clone());
} else {
colors_by_num_attrs[num_attrs + 1] =
colors_by_num_attrs[num_attrs + 1].union(&intersect)
}
colors_by_num_attrs[num_attrs] = colors_by_num_attrs[num_attrs].minus(&intersect)
}
}